package com.boot.security.server.controller;

import java.util.List;

import com.boot.security.server.model.AppAccount;
import com.boot.security.server.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boot.security.server.page.table.PageTableRequest;
import com.boot.security.server.page.table.PageTableHandler;
import com.boot.security.server.page.table.PageTableResponse;
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
import com.boot.security.server.dao.AppZdDoctorDao;
import com.boot.security.server.model.AppZdDoctor;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/appZdDoctors")
public class AppZdDoctorController {

    @Autowired
    private AppZdDoctorDao appZdDoctorDao;

    @PostMapping
    @ApiOperation(value = "保存")
    public AppZdDoctor save(@RequestBody AppZdDoctor appZdDoctor) {
        appZdDoctorDao.save(appZdDoctor);

        return appZdDoctor;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public AppZdDoctor get(@PathVariable Long id) {
        return appZdDoctorDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public AppZdDoctor update(@RequestBody AppZdDoctor appZdDoctor) {
        appZdDoctorDao.update(appZdDoctor);

        return appZdDoctor;
    }

    @GetMapping
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return appZdDoctorDao.count(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<AppZdDoctor> list(PageTableRequest request) {
                return appZdDoctorDao.list(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public void delete(@PathVariable Long id) {
        appZdDoctorDao.delete(id);
    }


    /**
     * 查询
     * @param appZdDoctor
     * 返回科室列表
     * @return R
     */
    @PostMapping("/find")
    public R findinfo(@RequestBody AppZdDoctor appZdDoctor){
        return new R<>( appZdDoctorDao.getBylist(appZdDoctor.getHostcode(),appZdDoctor.getDeptcode1(),appZdDoctor.getDeptcode2()));
        //    return new R<>(  bxbFbqksDao.getById(bxbFbqks.getId()));
    }
}
